package mo.offer_version2;

import mo.common.TreeNode;

public class L27 {

    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode reversed = new TreeNode(root.val);
        reversed.left = root.right;
        reversed.right = root.left;
        if (reversed.left != null) {
            reversed.left = mirrorTree(reversed.left);
        }
        if (reversed.right != null) {
            reversed.right = mirrorTree(reversed.right);
        }
        return reversed;
    }

    public static void main(String[] args) {
        L27 test = new L27();
        TreeNode treeNode = new TreeNode(4);
        treeNode.left = new TreeNode(2);
        treeNode.right = new TreeNode(7);
        TreeNode mirrorTree = test.mirrorTree(treeNode);
        System.out.println(mirrorTree);
    }
}
